<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/sharedfilecategory.tld" prefix="sfcat"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div style="padding:0 0 2px 0;">
<html:link page="/sf.mrqa?action=list">共享资料</html:link><sfcat:insert resultKind="navilinks"/>
</div>
<table class="mars">
    <html:form action="/sf" method="post" enctype="multipart/form-data" onsubmit="return validateSform(this);">
    <html:hidden property="action" value="modify"/>
    <input type="hidden" name="catId" value="<c:out value="${sharedfile.mrIaskSharedFileCategory.id}"/>"/>
   <tr class="even">
        <td align="right">附件</td>
        <td>
           <a href="<%=request.getContextPath()%>/sharedfile<c:out value="${sharedfile.path}"/>">
                        <c:out value="${sharedfile.name}"/>
            </a>
            <br>            
            <html:file property="file" size="80" onchange="fileChanged(this);"/>*
        </td>
    </tr>
    <tr>
        <td align="right">共享资料名称</td>
        <td>
            <html:text property="name" size="70" maxlength="30"/>*(如果不填写，默认为上载文件名字)
        </td>
    </tr> 
    <tr>
        <td align="right">共享资料描述</td>
        <td>
            <html:textarea property="description" cols="50" rows="5"/>
        </td>
    </tr> 
    <tr class="even">
        <td align="right"></td>
        <td>
            &nbsp;&nbsp;&nbsp;<input type="submit" value="保存共享资料"/>
        </td>
    </tr>
    </html:form>
</table>
<script type="text/javascript">
    /**
    *the file name changes according to selected local file
    */
    function fileChanged(pFile)
    {
        var fileName = pFile.value;
        var slashLastIndex = fileName.lastIndexOf("\\");
        var dotIndex = fileName.lastIndexOf(".");
        var shortFileName = fileName.substring(slashLastIndex+1,dotIndex);
        pFile.form.name.value=shortFileName;
    }

    function validateSform(pForm)
    {
        if(pForm.file.value == "")
        {
            alert("[文件]必须选择");
            pForm.file.focus();
            return false;
        }
        if(pForm.name.value == "")
        {
            alert("[名称]必须填写");
            pForm.name.focus();
            return false;
        }
        else
        {
            if(pForm.name.value.length < 2)
            {
                alert("[名称]必须大于2个字符");
                pForm.name.focus();
                return false;
            }
        }
        return true;
    }
</script>
